<template>
  <div>
    <van-empty v-if="list.length == 0" description="暂无地址" />
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="select"
    />
  </div>
</template>

<script>
import { reqaddresslist } from "../../http/http";
export default {
  data() {
    return {
      chosenAddressId: "",
      list: [],
    };
  },
  mounted() {
    this.chosenAddressId = Number(this.$route.query.id);
    //请求列表数据
    reqaddresslist({
      uid: JSON.parse(localStorage.getItem("isLogin")).uid,
    }).then((res) => {
      let arr = res.data.list ? res.data.list : [];
      this.list = arr.map((item) => {
        return {
          id: item.id,
          name: item.username,
          tel: item.userphone,
          address: item.location + item.useraddress,
          isDefault: item.status == 1,
        };
      });
    });
  },
  methods: {
    onAdd() {
      this.$router.replace("/a-add");
    },
    onEdit(item, index) {
      this.$router.replace("/a-add?id=" + item.id);
    },
    select(item) {
      this.$router.push("/order?addressId=" + item.id);
    },
  },
};
</script>

<style>
</style>